/*jslint vars: true, forin:true, sloppy: true*/
/*global angular, probe*/
probe.filter("decodeSave", function ($filter, scriptEngine) {
	return function (input) {
		var simple = false, out = null;

		scriptEngine.parse(input, {
			onComment: function (string) {
				if (string === '//simple case\n') {
					simple = true;
				}
			},
			//do not modify their code
			insertReturn: false
		})(function (err, ast) {
			//simple case
			if (simple) {
				out = angular.copy(ast.CONFIG);
				out.instructions = $filter("translateIns")(angular.copy(ast.PROCESSES.main.BODY.segment));
			} else {
				out = input;
			}
		});

		return {
			simple: simple,
			out: out
		};
	};
});